﻿using System;
using RootMotion.FinalIK;
using UnityEngine;

namespace RootMotion.Demos
{
	// Token: 0x020000D3 RID: 211
	[RequireComponent(typeof(InteractionSystem))]
	public class VRInteractionController : MonoBehaviour
	{
		// Token: 0x1700008F RID: 143
		// (get) Token: 0x0600062E RID: 1582 RVA: 0x00005FB6 File Offset: 0x000041B6
		// (set) Token: 0x0600062F RID: 1583 RVA: 0x00005FBE File Offset: 0x000041BE
		public InteractionSystem interactionSystem { get; set; }

		// Token: 0x17000090 RID: 144
		// (get) Token: 0x06000630 RID: 1584 RVA: 0x00005FC7 File Offset: 0x000041C7
		public float triggerProgress
		{
			get
			{
				if (this.triggerTime <= 0f)
				{
					return 0f;
				}
				return this.timer / this.triggerTime;
			}
		}

		// Token: 0x17000091 RID: 145
		// (get) Token: 0x06000631 RID: 1585 RVA: 0x00005FEC File Offset: 0x000041EC
		// (set) Token: 0x06000632 RID: 1586 RVA: 0x00005FF4 File Offset: 0x000041F4
		public InteractionTrigger currentTrigger { get; set; }

		// Token: 0x06000633 RID: 1587 RVA: 0x00005FFD File Offset: 0x000041FD
		public void Start()
		{
			this.interactionSystem = base.GetComponent<InteractionSystem>();
		}

		// Token: 0x06000634 RID: 1588 RVA: 0x000390AC File Offset: 0x000372AC
		public void LateUpdate()
		{
			int closestTriggerIndex = this.interactionSystem.GetClosestTriggerIndex();
			if (this.CanTrigger(closestTriggerIndex))
			{
				this.timer += Time.deltaTime;
				this.currentTrigger = this.interactionSystem.triggersInRange[closestTriggerIndex];
				if (this.timer >= this.triggerTime)
				{
					this.interactionSystem.TriggerInteraction(closestTriggerIndex, false);
					this.timer = 0f;
				}
				return;
			}
			this.timer = 0f;
			this.currentTrigger = null;
		}

		// Token: 0x06000635 RID: 1589 RVA: 0x0000600B File Offset: 0x0000420B
		public bool CanTrigger(int index)
		{
			return index != -1 && this.interactionSystem.TriggerEffectorsReady(index);
		}

		// Token: 0x04000560 RID: 1376
		[Range(0f, 10f)]
		[Tooltip("How long do we need to stare at triggers?")]
		public float triggerTime = 1f;

		// Token: 0x04000561 RID: 1377
		public float timer;
	}
}
